import java.util.Iterator;
import java.util.TreeSet;
import java.util.function.Consumer;

public class TreeSetDome {
    public static void main(String[] args) {

        TreeSet<Integer> ts = new TreeSet<>();
        ts.add(2);
        ts.add(4);
        ts.add(6);
        ts.add(3);
        ts.add(1);
        ts.add(5);
        System.out.println(ts);

        //遍历元素
        //1.迭代器
        System.out.println("迭代器遍历：");
        Iterator<Integer> it = ts.iterator();
        while (it.hasNext()) {
            int i = it.next();
            System.out.print(i+" ");
        }
        System.out.println(" ");
        System.out.println("---------------------------------");

        //2.增强for
        System.out.println("增强for遍历：");
        for (Integer i :ts){
            System.out.print(i+" ");
        }

        System.out.println(" ");
        System.out.println("---------------------------------");
        //3.lambda表达式
        System.out.println("lambda表达式遍历：");
        ts.forEach(integer->System.out.print(integer+" "));
    }
}
